package com.imooc.newretail.bpl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.imooc.newretail.bpl.entity.User;
import com.imooc.newretail.bpl.mapper.UserMapper;
import com.imooc.newretail.bpl.service.ITenantUserService;
import com.imooc.newretail.bpl.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 系统用户信息表 服务实现类
 * </p>
 *
 * @author Hank
 * @since 2020-06-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    ITenantUserService tenantUserService;

    /**
     * 删除某个用户，同时删除该用户所有的租户关联数据
     *
     * @param userId
     * @return
     */
    @Override
    @Transactional
    public boolean removeUser(String userId) {
        QueryWrapper query = new QueryWrapper();
        query.eq("user_id", userId);
        tenantUserService.remove(query);
        baseMapper.deleteById(userId);
        return true;
    }
}
